package cn.org.intelli.lims.o2oa.model;


import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.fun.DataProxy;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.ViewType;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTableType;
import xyz.erupt.annotation.sub_field.sub_edit.Search;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;
import java.util.UUID;

@Getter
@Setter
@Entity
@Table(name = "lims_material_op")
@SQLDelete(sql = "update lims_material_op set deleted = true, delete_time = now() where id = ?")
@Erupt(name = "耗材使用记录信息", dataProxy = MaterialOp.class, filter = @Filter("MaterialOp.deleted = false"))
public class MaterialOp implements DataProxy<MaterialOp> {

    @Id
    @EruptField(views = @View(title = "", type = ViewType.QR_CODE))
    private String id;
    @ManyToOne
    @EruptField(views = @View(title = "耗材信息", column = "desc.name"), edit = @Edit(title = "耗材信息", type = EditType.REFERENCE_TABLE, referenceTableType = @ReferenceTableType(id = "id", label = "desc.name"), search = @Search))
    private Material material;
    @ManyToOne
    @EruptField(views = @View(title = "案件信息", column = "slah"), edit = @Edit(title = "案件信息", type = EditType.REFERENCE_TABLE, referenceTableType = @ReferenceTableType(id = "id", label = "slah"), search = @Search))
    private Pcase pcase;
    @ManyToOne
    @EruptField(views = @View(title = "使用人员信息", column = "name"), edit = @Edit(title = "使用人员信息", type = EditType.REFERENCE_TABLE, referenceTableType = @ReferenceTableType(id = "id", label = "name"), search = @Search))
    private Person person;
    @Column(name = "op_time")
    @EruptField(views = @View(title = "使用时间"), edit = @Edit(title = "使用时间", search = @Search))
    private Date opTime;
    @Column(name = "delete_time")
    private Date deleteTime;
    private Boolean deleted = false;

    @Override
    public void beforeAdd(MaterialOp materialOp) {
        if (materialOp.getId() == null) {
            materialOp.setId(UUID.randomUUID().toString());
        }
    }
}
